package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhentao.domain.SLogs;
import com.zhentao.dto.LogShowDto;
import com.zhentao.mapper.LogsMapper;
import com.zhentao.result.Result;
import com.zhentao.service.SLogsService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author Lenovo
* @description 针对表【s_logs】的数据库操作Service实现
* @createDate 2024-08-12 09:56:26
*/
@Service
public class SLogsServiceImpl extends ServiceImpl<LogsMapper, SLogs>
    implements SLogsService{
    @Resource
    private LogsMapper logsMapper;

    @Scheduled(cron = "0 0 0 * * ?")
    public void deleteLogs(){
        Date date = new Date(System.currentTimeMillis()-(1000L *60*60*24*30));
        this.remove(Wrappers.<SLogs>lambdaQuery().ge(SLogs::getCreateTime,date));
    }

    @Override
    public Result getLogsAll(LogShowDto logShowDto) {
        System.out.println(logShowDto);
        PageHelper.startPage(logShowDto.getPageNum(),logShowDto.getPageSize());
        List<SLogs> logs= logsMapper.showByNameByType(logShowDto);
        PageInfo<SLogs> page = new PageInfo<>(logs);
        return Result.OK(page);
    }
}




